<?php

namespace app\modules\setting\configs\yjrwsz;

use sookie\excel\SaveExcel;
use yii\db\ActiveRecord;
use sookie\react\handlers\UrlHandler;
use yii\helpers\Json;
use app\modules\setting\models\yjrwsz\EtcRules;
use sookie\bootstraps\handlers\AuthChecker;

/**
* Class TestConfig
* @package sookie\react\configs
* app\modules\setting\configs\yjrwsz\DrwszConfig 模型的配置类
*/
class DrwszConfig{

    /**
    * @return array
    * 获取搜索表单配置
    */
    public static function getSearchConfig(){
    return [
            [
                "component" => "FormInput",
                "field" => "name",
                "label" => "名称",
                "placeholder" => "名称",
                "allowClear" => true,
            ],

    ];
    }

    /**
    * @return array
    * 获取表格的操作
    */
    public static function getTableActions(){
        return  [
            [
                "actionType" => "MODAL",
                "config" => [
                    "footer" => true,
                    "width" => 800,
                    "maskClosable" => true,
                    "title" => "新建",
                    "okText" => "提交",
                    "cancelText" => "取消",
                    "alert" => [
                        "type" => "info",
                        "message" => "小提示",
                        "width" => 600,
                        "description" => "请填写以下表单来新建数据"
                    ]
                ],
                "configUri" => UrlHandler::toAction("yjrwsz/drwsz","create"),
                "auth" => AuthChecker::doPermissionCheck("yjrwsz/drwsz","create"),
                "configParams" => new \ArrayObject(),
                "label" => "新建",
                "icon" => "plus",
                "type" => "primary",
            ],
        ];
    }

    /**
    * @return array
    * 获取表格行的操作
    * [] 表示要id, ["*"] 表示要一行记录,参数名record, ["id"] 指定需要的参数 ， selected_ids 表示需要所有选择的id
    * configParamsField 规定请求的时候带上数据行中的那些参数，只需要字段名
    */
    public static function getTableRowAction(){
        return [
            [
                "actionType" => "MODAL",
                "config" => [
                    "footer" => false,
                    "title" => "查看",
                    "alert" => [
                        "description" => "以下展示了该模型所有的字段信息"
                    ]
                ],
                "configUri" => UrlHandler::toAction("yjrwsz/drwsz","view"),
                "auth" => AuthChecker::doPermissionCheck("yjrwsz/drwsz","view"),
                "configParamsField" => ["id"],
                "label" => "查看"
            ],
            [
                "actionType" => "MODAL",
                "config" => [
                    "footer" => true,
                    "title" => "编辑",
                    "alert" => [
                        "description" => "填写以下表单修改数据模型"
                    ]
                ],
                "configUri" => UrlHandler::toAction("yjrwsz/drwsz","update"),
                "auth" => AuthChecker::doPermissionCheck("yjrwsz/drwsz","update"),
                "configParamsField" => ["id"],
                "label" => "编辑"
            ],
            [
                "actionType" => "CONFIRM",
                "method" => "post",
                "configUri" => UrlHandler::toAction("yjrwsz/drwsz","delete"),
                "auth" => AuthChecker::doPermissionCheck("yjrwsz/drwsz","delete"),
                "configParamsField" => ["id"],
                "label" => "删除"
            ],
        ];
    }

    /**
    * @return array
    * 获取表格配置
    */
    public static function getTableConfig(){
        return [
            "rowKey" => "id",
            "columns" => [
                [
                    "title" => "名称",
                    "dataIndex" => "name",
                    "sorter" => true,
                    "key" => "name",
                    "format" => "text",
                ],
//                [
//                    "title" => "发送数",
//                    "dataIndex" => "creators_per_job",
//                    "sorter" => true,
//                    "key" => "creators_per_job",
//                    "format" => "text",
//                ],
                [
                    "title" => "最近更新",
                    "dataIndex" => "update_at",
                    "sorter" => true,
                    "key" => "update_at",
                    "format" => "text",
                ],
            ],
            "actions" => self::getTableRowAction()
        ];
    }

    /**
    * 首页配置
    */
    public static function configIndex(){
        return [
            //搜索表单配置
            "searchConfig" => self::getSearchConfig(),
            // 操作配置 configParams 规定请求的时候带上那些参数
            "actionDivConfig" => self::getTableActions(),
            //表格配置
            "tableConfig" => self::getTableConfig(),
        ];
    }

    /**
    * @return array
    * 查看配置 format 可选 text pic video link
    */
    public static function configView(){
        return [
            "type" => "DETAIL",
            "config" => [
                [
                    "field" => "name",
                    "label" => "名称",
                    "format" => "text",
                ],
//                [
//                    "field" => "creators_per_job",
//                    "label" => "发送达人数",
//                    "format" => "text",
//                ],
                [
                    "field" => "product_num",
                    "label" => "选品数量",
                    "format" => "text",
                ],
                [
                    "field" => "goods_per_store",
                    "label" => "最大选品数",
                    "format" => "text",
                ],
                [
                    "field" => "min_sale",
                    "label" => "最低销量（0=不限）",
                    "format" => "text",
                ],
                [
                    "field" => "min_price",
                    "label" => "最低价格（0=不限）",
                    "format" => "text",
                ],
                [
                    "field" => "min_pf",
                    "label" => "最低评分（0=不限）",
                    "format" => "text",
                ],
                [
                    "field" => "min_yj",
                    "label" => "最低佣金比例（0=不限）",
                    "format" => "text",
                ],
                [
                    "field" => "is_bp",
                    "label" => "是否爆品",
                    "format" => "text",
                ],
                [
                    "field" => "is_new",
                    "label" => "是否新品",
                    "format" => "text",
                ],
                [
                    "field" => "is_brand",
                    "label" => "是否品牌",
                    "format" => "text",
                ],
                [
                    "field" => "drsj",
                    "label" => "导入时间，最近N天（0=不限）",
                    "format" => "text",
                ],
                [
                    "field" => "create_at",
                    "label" => "创建时间",
                    "format" => "text",
                ],
            ]
        ];
    }


    /**
    * @return array
    * 创建-表单配置
    */
    public static function configCreate(){
        return [
            "type" => "FORM",
            "formSubmitUri" => UrlHandler::toPage("yjrwsz/drwsz")."/create",
            "config" => [
                [
                    "component" => "FormInput",
                    "field" => "name",
                    "label" => "名称",
                    "placeholder" => "名称",
                    "allowClear" => true,
                    "initialValue" => "",
                    "rules" => [
                        [
                            'required'=> true,
                            'message' =>'必填项'
                        ]
                    ],
                ],
//                [
//                    "component" => "FormInput",
//                    "field" => "creators_per_job",
//                    "label" => "发送达人数",
//                    "placeholder" => "发送达人数",
//                    "allowClear" => true,
//                    "initialValue" => 500,
//                    "rules" => [],
//                ],
                [
                    "component" => "FormInput",
                    "field" => "product_num",
                    "label" => "选品数量",
                    "placeholder" => "选品数量",
                    "allowClear" => true,
                    "initialValue" => 6,
                    "rules" => [],
                ],
                [
                    "component" => "FormInput",
                    "field" => "goods_per_store",
                    "label" => "最大选品数",
                    "placeholder" => "最大选品数",
                    "allowClear" => true,
                    "initialValue" => 0,
                    "rules" => [],
                ],
                [
                    "component" => "FormInput",
                    "field" => "min_sale",
                    "label" => "最低销量（0=不限）",
                    "placeholder" => "最低销量（0=不限）",
                    "allowClear" => true,
                    "initialValue" => 0,
                    "rules" => [],
                ],
                [
                    "component" => "FormInput",
                    "field" => "min_price",
                    "label" => "最低价格（0=不限）",
                    "placeholder" => "最低价格（0=不限）",
                    "allowClear" => true,
                    "initialValue" => 0,
                    "rules" => [],
                ],
                [
                    "component" => "FormInput",
                    "field" => "min_pf",
                    "label" => "最低评分（0=不限）",
                    "placeholder" => "最低评分（0=不限）",
                    "allowClear" => true,
                    "initialValue" => 0,
                    "rules" => [],
                ],
                [
                    "component" => "FormInput",
                    "field" => "min_yj",
                    "label" => "最低佣金比例（0=不限）",
                    "placeholder" => "最低佣金比例（0=不限）",
                    "allowClear" => true,
                    "initialValue" => 0,
                    "rules" => [],
                ],
                [
                    "component" => "FormInput",
                    "field" => "is_bp",
                    "label" => "是否爆品",
                    "placeholder" => "是否爆品",
                    "allowClear" => true,
                    "initialValue" => 0,
                    "rules" => [],
                ],
                [
                    "component" => "FormInput",
                    "field" => "is_new",
                    "label" => "是否新品",
                    "placeholder" => "是否新品",
                    "allowClear" => true,
                    "initialValue" => 0,
                    "rules" => [],
                ],
                [
                    "component" => "FormInput",
                    "field" => "is_brand",
                    "label" => "是否品牌",
                    "placeholder" => "是否品牌",
                    "allowClear" => true,
                    "initialValue" => 0,
                    "rules" => [],
                ],
                [
                    "component" => "FormInput",
                    "field" => "drsj",
                    "label" => "导入时间，最近N天（0=不限）",
                    "placeholder" => "导入时间，最近N天（0=不限）",
                    "allowClear" => true,
                    "initialValue" => 0,
                    "rules" => [],
                ],
            ],
        ];
    }

    /**
    * @param ActiveRecord $model
    * @return array
    * 修改-表单配置
    */
    public static function configUpdate(ActiveRecord $model){
        return [
            "type" => "FORM",
            "formSubmitUri" => UrlHandler::toAction("yjrwsz/drwsz","update",["id" => $model->id]),
            "config" => [
                [
                    "component" => "FormInput",
                    "field" => "name",
                    "label" => "名称",
                    "placeholder" => "名称",
                    "allowClear" => true,
                    "initialValue" => $model->name,
                    "rules" => [
                        [
                            'required'=> true,
                            'message' =>'必填项'
                        ]
                    ],
                ],
//                [
//                    "component" => "FormInput",
//                    "field" => "creators_per_job",
//                    "label" => "发送达人数",
//                    "placeholder" => "发送达人数",
//                    "allowClear" => true,
//                    "initialValue" => $model->creators_per_job,
//                    "rules" => [],
//                ],
                [
                    "component" => "FormInput",
                    "field" => "product_num",
                    "label" => "选品数量",
                    "placeholder" => "选品数量",
                    "allowClear" => true,
                    "initialValue" => $model->product_num,
                    "rules" => [],
                ],
                [
                    "component" => "FormInput",
                    "field" => "goods_per_store",
                    "label" => "最大选品数",
                    "placeholder" => "最大选品数",
                    "allowClear" => true,
                    "initialValue" => $model->goods_per_store,
                    "rules" => [],
                ],
                [
                    "component" => "FormInput",
                    "field" => "min_sale",
                    "label" => "最低销量（0=不限）",
                    "placeholder" => "最低销量（0=不限）",
                    "allowClear" => true,
                    "initialValue" => $model->min_sale,
                    "rules" => [],
                ],
                [
                    "component" => "FormInput",
                    "field" => "min_price",
                    "label" => "最低价格（0=不限）",
                    "placeholder" => "最低价格（0=不限）",
                    "allowClear" => true,
                    "initialValue" => $model->min_price,
                    "rules" => [],
                ],
                [
                    "component" => "FormInput",
                    "field" => "min_pf",
                    "label" => "最低评分（0=不限）",
                    "placeholder" => "最低评分（0=不限）",
                    "allowClear" => true,
                    "initialValue" => $model->min_pf,
                    "rules" => [],
                ],
                [
                    "component" => "FormInput",
                    "field" => "min_yj",
                    "label" => "最低佣金比例（0=不限）",
                    "placeholder" => "最低佣金比例（0=不限）",
                    "allowClear" => true,
                    "initialValue" => $model->min_yj,
                    "rules" => [],
                ],
                [
                    "component" => "FormInput",
                    "field" => "is_bp",
                    "label" => "是否爆品",
                    "placeholder" => "是否爆品",
                    "allowClear" => true,
                    "initialValue" => $model->is_bp,
                    "rules" => [],
                ],
                [
                    "component" => "FormInput",
                    "field" => "is_new",
                    "label" => "是否新品",
                    "placeholder" => "是否新品",
                    "allowClear" => true,
                    "initialValue" => $model->is_new,
                    "rules" => [],
                ],
                [
                    "component" => "FormInput",
                    "field" => "is_brand",
                    "label" => "是否品牌",
                    "placeholder" => "是否品牌",
                    "allowClear" => true,
                    "initialValue" => $model->is_brand,
                    "rules" => [],
                ],
                [
                    "component" => "FormInput",
                    "field" => "drsj",
                    "label" => "导入时间，最近N天（0=不限）",
                    "placeholder" => "导入时间，最近N天（0=不限）",
                    "allowClear" => true,
                    "initialValue" => $model->drsj,
                    "rules" => [],
                ],
            ],
        ];
    }


}

